<?php
/**
 * @since      File available since Release v1.1
 */
defined('Inbearshop') or exit('Access Invalid!');
define('MYSQL_RESULT_TYPE',1);
class myControl extends BaseHomeControl{
	public function __construct(){
		parent::__construct();
        Language::read('indexs');
        Tpl::output('index_sign','index');
	}

	public function indexOp(){
		
		$userid = intval($_COOKIE['user_id']);				
		$model = Model();
		
		$help_link = $model->table('setting')->where(array('name'=>'help_link'))->find();
		Tpl::output('help_link',$help_link);
		
		$about_link = $model->table('setting')->where(array('name'=>'about_link'))->find();
		Tpl::output('about_link',$about_link);
				
		$user = $model->table('user')->where(array('user_id'=>$userid))->find();
		Tpl::output('user',$user);
		
		$fcount = $model->table('friend')->where(array('fid'=>$user['user_id']))->count();
		Tpl::output('fcount',$fcount);//粉丝数	 
		
		$mcount = $model->table('friend')->where(array('uid'=>$user['user_id']))->count();
		Tpl::output('mcount',$mcount);//关注数	
		
		$condition1 = array();
		$condition1['seller_id'] =  $userid;
		$sellernum = $model->table('order')->where($condition1)->count();
		Tpl::output('sellernum',$sellernum);//卖出
		
		$condition2 = array();
		$condition2['user_id'] =  $userid;
		$usernum = $model->table('order')->where($condition2)->count();
		Tpl::output('usernum',$usernum);//买入
		
		if(isset($_GET['type'])&&$_GET['type']==1){		
			//Tpl::showpage('like');
			Tpl::showpage('zsm/like');
		}else{
			
			//待发布
			$daifabu_condition = array();
			$daifabu_condition['seller_id'] = $_COOKIE['user_id'];
			$daifabu_condition['is_fabu'] = '0';			$daifabu_condition['Relation_zc_id'] = '0';
			$daifabu_auction_array = $model->table('auction')->where($daifabu_condition)->order('id desc')->select();
			
			//进行中
			$jinxing_condition = array();
			$jinxing_condition['seller_id'] = $_COOKIE['user_id'];
			$jinxing_condition['is_fabu'] = '1';
			$jinxing_condition['end_time'] = array('gt',time());
			$jinxing_condition['yikoujia_end'] = '0';
			$jinxing_auction_array = $model->table('auction')->where($jinxing_condition)->order('id desc')->select();
			
			Tpl::output('daifa_auction_array',$daifabu_auction_array);
			Tpl::output('jingxing_auction_array',$jinxing_auction_array);
	
	
			$table = C('tablepre').'auction';
			$time = time();
			$sql = "SELECT * FROM `{$table}` where (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `end_time`<'{$time}') or (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `yikoujia_end`=1) order by id desc limit 0,4";		
			$jiepai_auction_array = $model->query($sql);
			Tpl::output('jiepai_auction_array',$jiepai_auction_array);

			
			$sql = "SELECT count(*) FROM `{$table}` where (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `end_time`<'{$time}') or (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `yikoujia_end`=1) order by id desc limit 0,4";			
			$jiepai_count = $model->query($sql);
			Tpl::output('jiepai_count',$jiepai_count[0]['count(*)']);
			
			if($jiepai_count[0]['count(*)']>4){
				Tpl::output('haspage',1);
			}else{
				Tpl::output('haspage',0);
			}
			//Tpl::showpage('my');
			Tpl::showpage('zsm/my');
		}

	}

	public function likedataOp(){
		
		$userid = intval($_COOKIE['user_id']);
		
		$model = Model();
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*10;
		$limit = "{$nextnum},10";
		$auction = $model->table('like,auction')->join('left')->on('like.auction_id = auction.id')->where(array('user_id'=>$userid))->order('like.id desc')->limit($limit)->select();
		Tpl::output('auction',$auction);
		//Tpl::showpage('like.data');
		Tpl::showpage('zsm/like.data');
	}
	
	public function getjiepaidateOp(){
		
		$nextpage = intval($_GET['nextpage']);
		$nextnum = $nextpage*4;
		$limit = "{$nextnum},4";
		$model = Model();
		$table = C('tablepre').'auction';
		$time = time();
		$sql = "SELECT * FROM `{$table}` where (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `end_time`<'{$time}') or (`seller_id`='{$_COOKIE['user_id']}' and `is_fabu`='1' and `yikoujia_end`=1) order by id desc limit {$limit}";
		$jiepai_auction_array = $model->query($sql);
		Tpl::output('jiepai_auction_array',$jiepai_auction_array);
		
		if(empty($jiepai_auction_array)) exit;
		
		Tpl::showpage('my.jiepaidata');
	}
	
	
	/*
	 * 关注模块
	 */
	public function focusOp(){
		$userid = $_COOKIE['user_id'];
		$model = Model();
		if(isset($_GET['pagenum'])){
			$pagenum = intval($_GET['pagenum']);
			$pagesize = 10;
			$pagenum = $pagenum*$pagesize;
			$limit = "{$pagenum},{$pagesize}";
			$list = $model->table('friend,user')->join('left')->on('friend.fid = user.user_id')->where(array('uid'=>$userid))->order('friend.id desc')->limit($limit)->select();
			
			if(!empty($list)){
				foreach($list as $k=>$v){
					$level = array();
					$level['start'] = array('elt',$v['spoints']);
					$level['end'] = array('gt',$v['spoints']);
					$level['type'] = 1;
					$slevel = $model->table('level')->where($level)->find();
					$list[$k]['level'] = $slevel['name'];
				}
			}else{
				exit;
			}
			
			Tpl::output('list',$list);
			Tpl::showpage('focus.data');
			exit;
		}


		Tpl::showpage('focus');
	}
	
	/*
	 * 粉丝模块
	 */
	public function fansOp(){
		$userid = $_COOKIE['user_id'];
		if(isset($_GET['pagenum'])){
			$pagenum = intval($_GET['pagenum']);
			$pagesize = 10;
			$pagenum = $pagenum*$pagesize;
			$limit = "{$pagenum},{$pagesize}";
			$model = Model();
			$list = $model->table('friend,user')->join('left')->on('friend.uid = user.user_id')->where(array('fid'=>$userid))->order('friend.id desc')->limit($limit)->select();
			if(!empty($list)){
				foreach($list as $key=>$val){
					$condition = array();
					$condition['uid'] = $val['fid'];
					$condition['fid'] = $val['uid'];
					$res = $model->table('friend')->where($condition)->find();
					if(!empty($res)){
						$list[$key]['is_guanzhu'] = 1;
					}else{
						$list[$key]['is_guanzhu'] = 0;
					}
			
					$level = array();
					$level['start'] = array('elt',$val['spoints']);
					$level['end'] = array('gt',$val['spoints']);
					$level['type'] = 1;
					$slevel = $model->table('level')->where($level)->find();
					$list[$key]['level'] = $slevel['name'];
				}
			}else{
				exit;
			}	
				
			Tpl::output('list',$list);//买入
			Tpl::showpage('fans.data');//加载粉丝数据
			exit;
		}

		Tpl::showpage('fans');
	}

	/*
	 * 买家订单列表
	*/
	public function userorderOp(){
		$userid = $_COOKIE['user_id'];
		
		Tpl::showpage('userorder');
	}
	
	
	/*
	 * 买家订单数据
	*/
	public function userorderdataOp(){
		$userid = $_COOKIE['user_id'];
		$model = Model();
		$condition = array();
		$condition['order.user_id'] = $userid;
		if($_GET['state']!=''){
			$condition['order.order_state'] = intval($_GET['state']);
			if(intval($_GET['state'])=='0'){
				$condition['order.is_fail'] = '0';
			}
		}
		
		if(!empty($_GET['keyword'])){
			$condition['auction.auction_description'] = array('like',"%{$_GET['keyword']}%");
		}
		
		if(!empty($_GET['year'])&&!empty($_GET['month'])&&!empty($_GET['day'])){
			if($_GET['year']!='0000'){
				$end_time = strtotime($_GET['year'].'-'.$_GET['month'].'-'.$_GET['day']);
				$condition['auction.end_time'] = array('gt',$end_time);
			}
		}
		
		if(!empty($_GET['is_tuihuo'])){
			$condition['order.is_tuihuo'] = intval($_GET['is_tuihuo']);
		}
		
		$field = 'order.id as id,order.is_delay as is_delay,order.is_tuihuo as is_tuihuo,order.order_sn as order_sn,order.is_fail as is_fail,order.order_state as order_state,order.seller_name as seller_name,order.price as price,order.currentexchange as currentexchange,';
		$field.= 'order.fahuo_time as fahuo_time,order.tuihuo_express as tuihuo_express,order.reason as reason,order.is_deal as is_deal,order.add_time as add_time,order.shouhuo_time as shouhuo_time,order.order_comment as order_comment,order.is_accept as is_accept,order.is_tuihuo as is_tuihuo,';
		$field.= 'auction.auction_add_date as auction_add_date,auction.end_time as end_time,auction.auction_description as auction_description,auction.auction_img1 as auction_img1,auction.id as auction_id,user.user_id as seller_id,user.avatar as seller_avatar,order.user_id as user_id';
		
		$on = 'order.order_auction_id = auction.id,order.seller_id = user.user_id';
		
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*5;
		$limit = "{$nextnum},5";
		
		$list = $model->field($field)->table('order,auction,user')->join('left,left')->on($on)->where($condition)->order('order.id desc')->limit($limit)->select();
		
		Tpl::output('list',$list);
		Tpl::showpage('userorder.data');
	}
	
	/*
	 * 卖家订单列表
	 */
	public function sellerorderOp(){
		
		$userid = $_COOKIE['user_id'];
		
		Tpl::showpage('sellerorder');
	}
	
	/*
	 * 卖家订单数据
	 */
	public function sellerorderdataOp(){
		
		$userid = $_COOKIE['user_id'];
		$model = Model();
		$condition = array();
		$condition['order.seller_id'] = $userid;
		if($_GET['state']!=''){
			$condition['order.order_state'] = intval($_GET['state']);
			if(intval($_GET['state'])=='0'){
				$condition['order.is_fail'] = '0';
			}
		}
		
		if(!empty($_GET['keyword'])){
			$condition['auction.auction_description'] = array('like',"%{$_GET['keyword']}%");
		}
		
		if(!empty($_GET['year'])&&!empty($_GET['month'])&&!empty($_GET['day'])){
			if($_GET['year']!='0000'){
				$end_time = strtotime($_GET['year'].'-'.$_GET['month'].'-'.$_GET['day']);
				$condition['auction.end_time'] = array('gt',$end_time);
			}
		}
		
		$field = 'order.id as id,order.seller_id as seller_id,order.order_sn as order_sn,order.is_fail as is_fail,order.order_state as order_state,order.seller_name as seller_name,order.price as price,order.add_time as add_time,order.currentexchange as currentexchange,';
		$field.= 'order.tuihuo_express as tuihuo_express,order.add_time as add_time,order.shouhuo_time as shouhuo_time,order.order_comment as order_comment,order.is_tuihuo as is_tuihuo,order.is_accept as is_accept,';
		$field.= 'auction.auction_add_date as auction_add_date,auction.end_time as end_time,auction.auction_description as auction_description,auction.auction_img1 as auction_img1,auction.id as auction_id,user.user_id as user_id,user.avatar as user_avatar,user.nickname as nickname';
		
		$on = 'order.order_auction_id = auction.id,order.user_id = user.user_id';
		
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*5;
		$limit = "{$nextnum},5";
		
		$list = $model->field($field)->table('order,auction,user')->join('left,left')->on($on)->where($condition)->order('order.id desc')->limit($limit)->select();
			
		if(empty($list)) exit;
		
		Tpl::output('list',$list);
		Tpl::showpage('sellerorder.data');
	}
	
	public function sellerorderliupaiOp(){
		
		if(!empty($_POST)){
			$model = Model();
			$condition = array();
			$condition['seller_id'] = $_COOKIE['user_id'];
			$condition['id'] = intval($_POST['aid']);
			$condition['is_liupai'] = 2;
			$model->table('auction')->where($condition)->delete();
			
			echo json_encode(array('state'=>1));
			exit;
		}
		
		$model = Model();
		$condition = array();
		$condition['auction.seller_id'] = $_COOKIE['user_id'];
		$condition['auction.is_liupai'] = 2;
		
		if(!empty($_GET['keyword'])){
			$condition['auction.auction_description'] = array('like',"%{$_GET['keyword']}%");
		}
		
		if(!empty($_GET['year'])&&!empty($_GET['month'])&&!empty($_GET['day'])){
			if($_GET['year']!='0000'){
				$end_time = strtotime($_GET['year'].'-'.$_GET['month'].'-'.$_GET['day']);
				$condition['auction.end_time'] = array('gt',$end_time);
			}
		}
		
		$field = 'auction.*,user.avatar';
		$on = 'auction.seller_id = user.user_id';
		$list = $model->field($field)->table('auction,user')->join('left')->on($on)->where($condition)->order('auction.id desc')->select();
		
		Tpl::output('list',$list);
		Tpl::showpage('sellerorderliupai');
		
	}
	
	public function homeOp(){
		
		$model = Model();
		$memberhome = $model->table('user')->where(array('user_id'=>intval($_GET['uid'])))->find();
		
		
		$level = array();
		$level['start'] = array('elt',$memberhome['spoints']);
		$level['end'] = array('gt',$memberhome['spoints']);
		$level['type'] = 1;
		$slevel = $model->table('level')->where($level)->find();
		$memberhome['slevel'] = $slevel['name'];
		
		$level = array();
		$level['start'] = array('elt',$memberhome['upoints']);
		$level['end'] = array('gt',$memberhome['upoints']);
		$level['type'] = '0';
		$ulevel = $model->table('level')->where($level)->find();
		$memberhome['ulevel'] = $ulevel['name'];
		
		Tpl::output('memberhome',$memberhome);
		
		$condition = array();
		$condition['uid'] = $_COOKIE['user_id'];
		$condition['fid'] = $memberhome['user_id'];
		$guanzhu = $model->table('friend')->where($condition)->find();
		if(!empty($guanzhu)){
			Tpl::output('guanzhu','1');
		}else{
			Tpl::output('guanzhu','0');
		}
		
		$condition_pingbi = array();
		$condition_pingbi['seller_id'] = $_COOKIE['user_id'];
		$condition_pingbi['user_id'] = intval($_GET['uid']);
		
		//屏蔽
		$pingbi = $model->table('pingbi')->where($condition_pingbi)->find();	
		Tpl::output('pingbi',$pingbi);
				
		$auction_condition = array();
		$auction_condition['seller_id'] = $memberhome['user_id'];
		$auction_condition['is_fabu'] = 1;
		$auction_condition['is_state'] = '0';
		$auction = $model->table('auction')->where($auction_condition)->order('id desc')->select();
		Tpl::output('auction',$auction);
				
		//seller pingfen
		$pingfen = array();
		$pingfen['order_state'] = '3';
		$pingfen['is_fail'] = '0';
		$pingfen['order_comment'] = array('neq','');
		$pingfen['seller_id'] = intval($_GET['uid']);
		
		$pingfen_sum = $model->table('order')->where($pingfen)->sum('order_score');
		$pingfen_count = $model->table('order')->where($pingfen)->count();
		$seller_pingfen = $pingfen_count=='0'?'0.00':number_format(($pingfen_sum/$pingfen_count),2);
		Tpl::output('seller_pingfen',$seller_pingfen);
		
		//seller weiyue
		$s_weiyue = array();
		$s_weiyue['order_state'] = '1';
		$s_weiyue['is_fail'] = '1';
		$s_weiyue['seller_id'] = intval($_GET['uid']);		
		$s_weiyue_count = $model->table('order')->where($s_weiyue)->count();
		
		$s_weiyue = array();
		$s_weiyue['is_fail'] = '1';
		$s_weiyue['seller_id'] = intval($_GET['uid']);
		$s_count = $model->table('order')->where($s_weiyue)->count();
		
		$seller_weiyue = $s_count == '0'?'0':number_format(($s_weiyue_count/$s_count),2);	
		Tpl::output('seller_weiyue',$seller_weiyue);
		
		
		//user weiyue		
		$u_weiyue = array();
		$u_weiyue['order_state'] = '0';
		$u_weiyue['is_fail'] = '1';
		$u_weiyue['user_id'] = intval($_GET['uid']);
		$u_weiyue_count = $model->table('order')->where($u_weiyue)->count();

		$u_weiyue = array();
		$u_weiyue['user_id'] = intval($_GET['uid']);
		$u_count = $model->table('order')->where($u_weiyue)->count();
		
		
		$user_weiyue = $u_count=='0'?'0':number_format(($u_weiyue_count/$u_count),2);
		Tpl::output('user_weiyue',$user_weiyue);
	
		//user tuihuo
		$s_tuihuo = array();
		$s_tuihuo['order_state'] = '3';
		$s_tuihuo['is_tuihuo'] = '1';
		$s_tuihuo['user_id'] = intval($_GET['uid']);
		$s_tuihuo_count = $model->table('order')->where($s_tuihuo)->count();
		
		$s_tuihuo = array();
		$s_tuihuo['order_state'] = '3';
		$s_tuihuo['user_id'] = intval($_GET['uid']);
		$s_tuihuo = $model->table('order')->where($s_tuihuo)->count();
		$user_tuihuo = $s_tuihuo=='0'?'0':number_format(($s_tuihuo_count/$s_tuihuo),2);
		Tpl::output('user_tuihuo',$user_tuihuo);
		
		$order_condition = array();
		$order_condition['seller_id'] = intval($_GET['uid']);
		$order_condition['user_id'] = $_COOKIE['user_id'];		
		$order = $model->table('order')->where($order_condition)->find();
		
		if(empty($order)){
			$order_condition = array();
			$order_condition['seller_id'] = $_COOKIE['user_id'];
			$order_condition['user_id'] = intval($_GET['uid']);
			$order = $model->table('order')->where($order_condition)->find();
		}
		
		if(!empty($order)){
			Tpl::output('is_show',1);
		}else{
			Tpl::output('is_show',0);
		}
		
		Tpl::showpage('memberhome');
	}
	
	public function mysendoutOp(){
		$user_id = $_COOKIE['user_id'];
		$auction_id = intval($_GET['auction_id']);
		
		$condition = array();
		$condition['order_auction_id'] = $auction_id;
		$condition['user_id'] = $user_id;
		
		$model = Model();
		$order = $model->table('order')->where($condition)->find();
		$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
		if(empty($order)){
			echo json_encode(array('state'=>0,'msg'=>'参数错误'));
			exit;
		}
		
		if($order['order_state']>2){
			echo json_encode(array('state'=>0,'msg'=>'参数错误'));
			exit;
		}
		

		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();

		
		$res = $model->table('order')->where($condition)->update(array('order_state'=>3,'shouhuo_time'=>time()));
		if($res){
			
			$stime = strtotime(date("Y-m-d"));
			$etime = $stime+3600*24;
			
			$s = array();
			$s['shouhuo_time'] = array('between',"{$stime},{$etime}");
			$s['order_state'] = 3;
			$s['seller_id'] = $order['seller_id'];
			$s['user_id'] = $order['user_id'];
			
			$r = $model->table('order')->where($s)->count();

			if(($r<2)&&$order['currentexchange']!=1){
				$upoints = ceil($order['price']/10);
				$user_condition = array();
				$user_condition['user_id'] = $order['user_id'];
				$model->table('user')->where($user_condition)->setInc('upoints',$upoints);
				
				$spoints = '';
				if($order['price']<250){
					$spoints = 1;
				}elseif(($order['price']<500)&&($order['price']>=250)){
					$spoints = 2;
				}elseif(($order['price']<2000)&&($order['price']>=500)){
					$spoints = 3;
				}elseif(($order['price']<16000)&&($order['price']>=2000)){
					$spoints = 4;
				}elseif($order['price']>=16000){
					$spoints = 5;
				}
				$seller_condition = array();
				$seller_condition['user_id'] = $order['seller_id'];
				$model->table('user')->where($seller_condition)->setInc('spoints',$spoints);
			}
		
			$order = $model->table('order')->where(array('order_auction_id'=>$auction_id))->find();
			$message = "买家确认收货！ <br>尊敬的卖家，您的拍品买家已经收货";
			$this->addsellerlog($auction_id,$message,$order['seller_id']);
			

			$seller = $model->table('user')->where(array('user_id'=>$order['seller_id']))->find();
			
			if($auction['cashprice']>0){
				//卖家保证金退还
				$seller_cash_log = $model->table('cash_log')->where(array('user_id'=>$order['seller_id'],'auction_id'=>$auction_id))->find();
				if($seller_cash_log['paymentname']=='weixin'){
					require_once BASE_ROOT_PATH."/shop/templates/default/home/WxPayPubHelper/WxPayPubHelper.php";
					$out_trade_no = $seller_cash_log['pre_order_sn'];
					$refund_fee = $seller_cash_log["cprice"]*100;
					//商户退款单号，商户自定义，此处仅作举例
					$out_refund_no = "refund_scash_sn".time();
					//总金额需与订单号out_trade_no对应，demo中的所有订单的总金额为1分
					$total_fee = $seller_cash_log["cprice"]*100;
					//使用退款接口
					$refund = new Refund_pub();
					$refund->setParameter("out_trade_no","$out_trade_no");//商户订单号
					$refund->setParameter("out_refund_no","$out_refund_no");//商户退款单号
					$refund->setParameter("total_fee","$total_fee");//总金额
					$refund->setParameter("refund_fee","$refund_fee");//退款金额
					$refund->setParameter("op_user_id",WxPayConf_pub::MCHID);//操作员
					//调用结果
					$refundResult = $refund->getResult();
					
					$params = array();
					$params['user_id'] = $order['seller_id'];
					$params['mingxi_type'] = '0';
					$params['mingxi_price'] = $auction['cashprice'];
					$params['add_time'] = time();
					$params['mingxi_reason'] = '保证金退还';
					$params['mingxi_pos'] = '1';
					$model->table('mingxi')->insert($params);
					
					$data = array();
					$data1 = array();
					$data['touser'] = $seller['openid'];
					$data['template_id'] = $this->getTemplateId(6);
					$data['url'] = BASE_SITE_URL.'/index.php?act=order&op=ordersellerdetail&auction_id='.$auction['id'];
					$data['data']['first']['value'] = "尊敬的【{$seller['nickname']}】,您参与的‘{$auction['auction_description']}’付款成功，保证金退还至您微信钱包";					
					$data['data']['reason']['value'] = '付款成功';
					$data['data']['refund']['value'] = $auction['cashprice'].'元';
					$data['data']['remark']['value'] = '如未收到退款，请联系客服';
				}else{
					$model->table('user')->where(array('user_id'=>$order['seller_id']))->setInc('price',$auction['cashprice']);
					
					$data = array();
					$data1 = array();
					$data['touser'] = $seller['openid'];
					$data['template_id'] = $this->getTemplateId(6);
					$data['url'] = BASE_SITE_URL.'/index.php?act=order&op=ordersellerdetail&auction_id='.$auction['id'];
					$data['data']['first']['value'] = "尊敬的【{$seller['nickname']}】,您参与的‘{$auction['auction_description']}’付款成功，保证金退还至您的余额";					
					$data['data']['reason']['value'] = '付款成功';
					$data['data']['refund']['value'] = $auction['cashprice'].'元';
					$data['data']['remark']['value'] = '如未收到退款，请联系客服';
					
					$params = array();
					$params['user_id'] = $order['seller_id'];
					$params['mingxi_type'] = '0';
					$params['mingxi_price'] = $auction['cashprice'];
					$params['add_time'] = time();
					$params['mingxi_reason'] = '保证金退还';
					$params['mingxi_pos'] = '0';
					$model->table('mingxi')->insert($params);
				}
				$data1 = json_encode($data);
				$this->send_template_message($data1);
			}
			
			if($order['currentexchange']==1){
				
				$data = array();
				$data1 = array();
				$data['touser'] = $seller['openid'];
				$data['template_id'] = $this->getTemplateId(13);
				$data['url'] = BASE_SITE_URL.'/index.php?act=order&op=ordersellerdetail&auction_id='.$order['order_auction_id'];
				$data['data']['first']['value'] = "尊敬的【{$seller['nickname']}】,您的拍品买家已确认收货";
				$data['data']['keyword1']['value'] = "{$order['order_sn']}";
				$data['data']['keyword2']['value'] = "{$auction['auction_description']}";
				$data['data']['keyword3']['value'] = date("Y-m-d H:i",$order['add_time']);
				$data['data']['keyword4']['value'] = date("Y-m-d H:i",$order['fahuo_time']);
				$data['data']['keyword5']['value'] = date("Y-m-d H:i");
				//$data['data']['remark']['value'] = "提醒：交易完成，拍卖款项：{$order['price']}元，已经打入您的余额";
				$data1 = json_encode($data);
				$this->send_template_message($data1);
				
				echo json_encode(array('state'=>1));
				exit;
			}else{
				
				$setting =  F('bearshopsetting');
				$is_charge = $setting['is_charge'];
				if($is_charge>0){//佣金比例
					$totalprice = $order['price']-($order['price']*$setting['is_charge']/100);
					$price = $seller['price']+$totalprice;
					$model->table('user')->where(array('user_id'=>$order['seller_id']))->update(array('price'=>$price));
				}else{
					$totalprice = $order['price'];
					$price = $seller['price']+$order['price'];
					$model->table('user')->where(array('user_id'=>$order['seller_id']))->update(array('price'=>$price));
				}
				

					
				$params = array();
				$params['user_id'] = $order['seller_id'];
				$params['mingxi_type'] = '0';
				$params['mingxi_price'] = $totalprice;
				$params['add_time'] = time();
				$params['mingxi_reason'] = '拍品货款到账';
				$params['mingxi_pos'] = '0';
				$model->table('mingxi')->insert($params);
					
					
				$data = array();
				$data1 = array();
				$data['touser'] = $seller['openid'];
				$data['template_id'] = $this->getTemplateId(13);
				$data['url'] = BASE_SITE_URL.'/index.php?act=order&op=ordersellerdetail&auction_id='.$order['order_auction_id'];
				$data['data']['first']['value'] = "尊敬的【{$seller['nickname']}】,您的拍品买家已确认收货";
				$data['data']['keyword1']['value'] = "{$order['order_sn']}";
				$data['data']['keyword2']['value'] = "{$auction['auction_description']}";
				$data['data']['keyword3']['value'] = date("Y-m-d H:i",$order['add_time']);
				$data['data']['keyword4']['value'] = date("Y-m-d H:i",$order['fahuo_time']);
				$data['data']['keyword5']['value'] = date("Y-m-d H:i");
				$data['data']['remark']['value'] = "提醒：交易完成，拍卖款项：{$totalprice}元，已经打入您的余额";
				$data1 = json_encode($data);
				$this->send_template_message($data1);
			}


			
			echo json_encode(array('state'=>1));
			exit;
		}else{
			echo json_encode(array('state'=>0));
			exit;
		}
	}
	
	

	
	public function myinfoOp(){
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		if(empty($user)){
			exit;
		}
		Tpl::output('user',$user);	

		$condition1 = array();
		$condition1['order_state'] = '0';
		$condition1['is_fail'] = '0';
		$condition1['user_id'] = $_COOKIE['user_id'];
		$count1 = $model->table('order')->where($condition1)->count();
		
		$condition2 = array();
		$condition2['order_state'] = '1';
		$condition2['is_fail'] = '0';
		$condition2['user_id'] = $_COOKIE['user_id'];
		$count2 = $model->table('order')->where($condition2)->count();
		
		$condition3 = array();
		$condition3['order_state'] = '2';
		$condition3['is_fail'] = '0';
		$condition3['user_id'] = $_COOKIE['user_id'];
		$count3 = $model->table('order')->where($condition3)->count();
		
		Tpl::output('count1',$count1);
		Tpl::output('count2',$count2);
		Tpl::output('count3',$count3);
		
		Tpl::showpage('myinfo');
	}
	
	public function paysaftOp(){	
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		if(empty($user)){
			exit;
		}
		
		Tpl::output('user',$user);
		Tpl::showpage('paysaft');
	}
	
	public function idcardOp(){
		
		if(isset($_POST)&&!empty($_POST)){
			$params = array();
			$params['cardname'] = trim($_POST['name']);
			$params['cardid'] = trim($_POST['idCode']);
			
			$condition = array();
			$condition['user_id'] = $_COOKIE['user_id'];
			
			$model = Model();
			$res = $model->table('user')->where($condition)->update($params);
			if($res){
				echo json_encode(array('state'=>1));
			}
			exit;
		}
		
		$user_id = $_COOKIE['user_id'];
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
		if(empty($user)){
			exit;
		}
		Tpl::output('user',$user);
		Tpl::showpage('idcard');
	}
	
	public function resetpwdOp(){
		if(isset($_POST)&&!empty($_POST)){
			$user_id = $_COOKIE['user_id'];
			$model = Model();
			$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
			if(empty($user)){
				echo json_encode(array('state'=>'0','error'=>'用户不存在'));
				exit;
			}
			
			if($user['paypasswd']!=md5($_POST['cpasswd'])){
				echo json_encode(array('state'=>'0','error'=>'支付密码不正确'));
				exit;
			}
			
			$params = array();
			$params['paypasswd'] = md5($_POST['npasswd']);
			
			$model = Model();
			$res = $model->table('user')->where(array('user_id'=>$user_id))->update($params);
			if($res){
				echo json_encode(array('state'=>1));
			}
			exit;
		}
		
		$user_id = $_COOKIE['user_id'];
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
		if(empty($user)){
			exit;
		}
		Tpl::output('user',$user);
		Tpl::showpage('resetpwd');
	}
	
	public function forgetpwdOp(){
		
		if(isset($_POST)&&!empty($_POST)){
			
			$condition = array();
			$condition['user_id'] = $_COOKIE['user_id'];
			$condition['cardname'] = trim($_POST['name']);
			$condition['cardid'] = trim($_POST['idCode']);

			$model = Model();
			$user = $model->table('user')->where($condition)->find();
			if(empty($user)){
				echo json_encode(array('state'=>'0','error'=>'姓名、身份证号输入错误哦'));
				exit;
			}else{
				$str = md5($condition['cardid']);
				echo json_encode(array('state'=>'1','label'=>$str));
				exit;
			}	
		}
		$user_id = $_COOKIE['user_id'];
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
		if(empty($user)){
			exit;
		}
		Tpl::output('user',$user);
		Tpl::showpage('forgetpwd');
	}
	
	public function forgetpwds1Op(){
		if(!empty($_POST)){
			$model = Model();
			$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
			if(empty($user)){
				echo json_encode(array('state'=>0));
				exit;
			}
			
			if($_POST['label']!=md5($user['cardid'])){
				echo json_encode(array('state'=>0));
				exit;
			}
			
			$res = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update(array('paypasswd'=>md5($_POST['paypasswd'])));

			echo json_encode(array('state'=>1));
			exit;
		}
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		if(empty($user)){
			exit;
		}
		
		if(md5($user['cardid']) != $_GET['label']){
			exit;
		}
		
		Tpl::output('user',$user);
		Tpl::showpage('forgetpwds1');
	}
	
	
	public function cancelguanzhuOp(){	
		$model = Model();
		$condition = array();
		$condition['uid'] = intval($_GET['uid']);
		$condition['fid'] = intval($_GET['fid']);
		
		$friend = $model->table('friend')->where($condition)->find();
		if(empty($friend)){
			echo json_encode(array('state'=>'0'));
			exit;
		}
		
		$res = $model->table('friend')->where($condition)->delete();
		if($res){
			echo json_encode(array('state'=>'1'));
			exit;
		}else{
			echo json_encode(array('state'=>'0'));
			exit;
		}		
	}
	
	public function popguanzhuOp(){
		$model = Model();
		$auction = $model->table('auction')->where(array('id'=>intval($_GET['auction_id'])))->find();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		
		
		$params = array();
		$params['uid'] = $user['user_id'];
		$params['fid'] = $auction['seller_id'];
		
		$friend = $model->table('friend')->where($params)->find();
		if(!empty($friend)) exit;
		
		$insert_array = array();
		$insert_array['uid'] = $user['user_id'];
		$insert_array['uname'] = $user['nickname'];
		$insert_array['fid'] = $auction['seller_id'];
		$insert_array['fname'] = $auction['seller_name'];
		
		$model->table('friend')->insert($insert_array);
		echo json_encode(array('state'=>1));
		exit;
	}
	
	public function guanzhuOp(){
		$uid = intval($_GET['uid']);
		$fid = intval($_GET['fid']);
		
		$model = Model();
		$uidinfo = $model->table('user')->where(array('user_id'=>$uid))->find();
		$fidinfo = $model->table('user')->where(array('user_id'=>$fid))->find();
		
		if(empty($uidinfo) || empty($fidinfo)){
			echo json_encode(array('state'=>0));
			exit;
		}
		
		
		$params = array();
		$params['uid'] = $uidinfo['user_id'];		
		$params['fid'] = $fidinfo['user_id'];
		
		$friend = $model->table('friend')->where($params)->find();
		if(!empty($friend)){
			echo json_encode(array('state'=>0));
			exit;
		}
		
		$params['uname'] = $uidinfo['nickname'];
		$params['fname'] = $fidinfo['nickname'];
		
		$res = $model->table('friend')->insert($params);
		if($res){
			echo json_encode(array('state'=>1));
			exit;
		}else{
			echo json_encode(array('state'=>0));
			exit;
		}
	}
	
	public function editinfoOp(){
		
		if(!empty($_POST)){
			$params = array();
			
			if(in_array($_POST['field'], array('mobile','wxaccount','signature','contract'))){
				$params[$_POST['field']] = $_POST['value'];
			}else{
				echo json_encode(array('state'=>1,'error'=>'异常操作'));
				exit;
			}
						
			$model = Model();
			$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);
			echo json_encode(array('state'=>1));
			exit;
		}
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		
		if($_GET['type']=='mobile'){
			Tpl::showpage('mobile');
		}else{
			Tpl::showpage('editinfo');
		}
	}
	
	
	public function messageOp(){
		$model = Model();
		
		if(!empty($_GET['type'])){
			$condition = array();
			$condition['order.user_id'] = $_COOKIE['user_id'];
			$field = 'auction.id as id,order.user_id as user_id,order_sn as order_sn,auction.auction_description as auction_description,auction.auction_img1 as auction_img1';
			$auction = $model->field($field)->table('auction,order')->join('left')->on('auction.auction_order_sn = order.order_sn')->where($condition)->order('auction.id desc')->select();
			
		}else{
			$auction = $model->table('auction')->where(array('seller_id'=>$_COOKIE['user_id']))->order('id desc')->select();
		}
		
		if(!empty($auction)){
			foreach($auction as $k=>$val){
				$condition = array();
				$condition['auction_id'] = $val['id'];
				if(!empty($_GET['type'])){
					$condition['uid'] = $val['user_id'];
				}else{
					$condition['uid'] = $_COOKIE['user_id'];
				}
				
				$auction[$k]['seller_log'] = $model->table('seller_log')->where($condition)->order('add_time desc')->select();
			}
		}
		
		Tpl::output('auction',$auction);
		Tpl::showpage('message');
	}
	
	
	public function tixianOp(){
		
		$setting =  F('bearshopsetting');
		$is_tixian = $setting['is_tixian'];
		
		if(isset($_POST)&&!empty($_POST)){
			$model = Model();
			$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
			
			$price = (float)$_POST['price'];//小熊Shop编辑信息
			if($price==0){
				echo json_encode(array('state'=>'0','error'=>'请填写提现金额！'));
				exit;
			}
			
			if($price>$user['price']){
				echo json_encode(array('state'=>'0','error'=>'提现金额不能大于余额'));
				exit;
			}
			
			
			if($price>$is_tixian){
				echo json_encode(array('state'=>'0','error'=>"提现金额不能大于{$is_tixian}"));
				exit;
			}
			
			$params = array();
			$params['user_id'] = $_COOKIE['user_id'];
			$params['nickname']= $user['nickname'];
			$params['price'] = $price;
			$params['add_time'] = time();
			
			$res = $model->table('tixian')->insert($params,true);
			if($res){
				$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->setDec('price',$price);
				$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->setInc('freezeprice',$price);
				echo json_encode(array('state'=>'1','tixian_id'=>$res));
			}else{
				echo json_encode(array('state'=>'0'));
			}
			exit;
		}
		
		$today = strtotime(date("Y-m-d"));
		$tom = $today+3600*24;
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		
		
		$condition = array();
		$condition['user_id'] = $_COOKIE['user_id'];
		$condition['add_time'] = array("between","{$today},{$tom}");
		$tixian = $model->table('tixian')->where($condition)->select();

		if($user['is_company']==1){
			if(count($tixian)>=2){
				$this->showTip('您今天已经提交2次提现申请，每天只能提交2次');
			}
		}else{
			if(!empty($tixian)){
				$this->showTip('您今天已经提交提现申请，每天只能提交一次');
			}
		}
		
		Tpl::output('is_tixian',$is_tixian);
		Tpl::showpage('payment.tixian');
	}
	
	
	/*
	 * 提现成功页面
	 */
	public function tipsuccessOp(){
		
		$model = Model();
		$tixian = $model->table('tixian')->where(array('id'=>intval($_GET['tixian_id'])))->find();
		Tpl::output('tixian',$tixian);
		
		Tpl::showpage('payment.tipsuccess');
	}
	
	public function sendaddrOp(){
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();		
		$seller = $model->table('user')->where(array('user_id'=>$_GET['seller_id']))->find();
		
		$wx_name_arr = F('wxaccount');
		$wx_name = $wx_name_arr['wx_name'];

		$url = BASE_SITE_URL.'/index.php?act=shop&op=index&seller_id='.$seller['user_id'];
		$content = "{$seller['nickname']}的{$wx_name}拍卖地址：";
		$content = $content.$url;		
		
		$txt = '{
					"touser":"'.$user['openid'].'",
					"msgtype":"text",
					"text":{
						"content":"'.$content.'"
					}
				}';
		
		$access_token = $this->getAccessTokenIn();
		
		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}";		
		$d = $this->https_request($url,$txt);
		$d = json_decode($d,true);
		if($d['errmsg']!='ok'){
			$access_token = $this->getAccessToken();
			$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}";
			$this->https_request($url,$txt);
		}
		
		echo json_encode(array('state'=>'1')); 
		exit;
		
	}
	
	private function unicode2utf8($str){
	        if(!$str) return $str;
	        $decode = json_decode($str);
	        if($decode) return $decode;
	        $str = '["' . $str . '"]';
	        $decode = json_decode($str);
	        if(count($decode) == 1){
	                return $decode[0];
	        }
	        return $str;
	}
	public function qrcodeOp(){
		

		
		$seller_id = intval($_GET['seller_id']);
		$model = Model();
		$seller = $model->table('user')->where(array('user_id'=>$seller_id))->find();
		
		Tpl::output('seller',$seller);
		Tpl::showpage('qrcode');
	}
	
	public function getqrcodeOp(){
		include "./phpqrcode.php";
		$url = BASE_SITE_URL.'/index.php?act=index&seller_id='.$_GET['seller_id'];
		QRcode::png($url);
	}
	
	
		public function zc_shenqingOp(){		$model = Model();		$params["zc_id"]=$_GET["current_id"];		$params["user_id"]=$_GET["user_id"];		$params["status"]=0;		$special = $model->table('special')->where(array('id'=>$_GET["current_id"]))->find();		$special_sq = $model->table('zc_shenqing')->where(array('zc_id'=>$_GET["current_id"],'user_id'=>$_GET["user_id"]))->find();							 if(time()>$special["start_time"] && time()<$special["end_time"]){			echo "专场正在进行中，不能申请！！！";		}		elseif(!empty($special_sq)){			echo "您已经申请过该专场请不要重复申请！！";		}		else{			$model->table('zc_shenqing')->insert($params);		echo "您的申请请求发送成功，等待管理员审核！！";		} 					}	public function zc_shenqing_cxOp(){		$model = Model();		$params["id"]=$_GET["sq_id"];		$params["user_id"]=$_GET["user_id"];		$special = $model->table('special')->where(array('id'=>$_GET["current_id"]))->find();		$special_sq = $model->table('zc_shenqing')->where(array('zc_id'=>$_GET["current_id"],'user_id'=>$_GET["user_id"],'status'=>0))->find();							 if(time()>$special["start_time"] && time()<$special["end_time"]){			echo "专场正在进行中，不能申请！！！";		}		elseif(!empty($special_sq)){			echo "您已经申请过该专场请不要重复申请！！";		}		else{			$model->table('zc_shenqing')->where($params)->update(array('status'=>0));		echo "您的申请请求发送成功，等待管理员审核！！";		}					}
	public function updatesnOp(){
		$model = Model();
		$params = array();
		$params['company_order_sn'] = $this->snOrder();
		
		$res = $model->table('company')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);
		if($res){
			echo json_encode(array('state'=>1));
		}
		exit;
		
	}	public function free_updatesnOp(){		$model = Model();		$params = array();		$params['company_order_sn'] = $this->snOrder();		$params['company_state'] = 3;		$params['company_add_time'] = time();				$res = $model->table('company')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);						$zym_10 = $model->table('company')->where(array('user_id'=>$_COOKIE['user_id']))->find();		$zym_22 = array();	  $zym_22['is_company'] = 1;	  $zym_22['is_company_type'] = $zym_10['company_type']; 	  $zym_22['company_valid'] = strtotime(date('Y') + 1 . '-' . date('m-d H:i:s'));	  $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($zym_22);	  	  	  $zym_24 = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();				$zym_21 = F('wxaccount'); 	  $zym_18 = $zym_21['wx_name'];	  $zym_17 = "实名认证申请通知：\n{$zym_24['nickname']},恭喜！您({$zym_18})店铺实名认证已通过。\n";	  $zym_17.='<a href=\''.BASE_SITE_URL.'/index.php?act=renzheng&op=renzheng\'>查看更多认证详情</a>'; 	  $zym_13 = '{' . "\xd\xa\x9\x9\x9\x9\x9" . '"touser":"'.$zym_24['openid'].'",' . "\xd\xa\x9\x9\x9\x9\x9" . '"msgtype":"text",' . "\xd\xa\x9\x9\x9\x9\x9" . '"text":{' . "\xd\xa\x9\x9\x9\x9\x9\x9" . '"content":"'.$zym_17.'"' . "\xd\xa\x9\x9\x9\x9\x9" . '}' . "\xd\xa\x9\x9\x9\x9" . '}';	  $zym_14 = $this->getAccessTokenIn();	  $zym_15 = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$zym_14}";	  $zym_16 = $this->https_request($zym_15,$zym_13); 	  $zym_16 = json_decode($zym_16,true);	  echo json_encode(array('state'=>1));	 	  	}
	
	public function sellerinfoOp(){
		
		if(isset($_POST) &&!empty($_POST)){
			$params = array();
			$params['mobile'] = $_POST['mobile'];
			$params['spassword'] = md5($_POST['spassword']);
			
			$model = Model();
			$res = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);
			echo json_encode(array('state'=>1));
			exit;
		}
		
		$model = Model();
		$seller = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();

		Tpl::output('seller',$seller);
		Tpl::showpage('sellerinfo');
	}
	
	
	public function renpaymentOp(){
		
		$condition = array();
		$condition['user_id'] = $_COOKIE['user_id'];
		//$condition['company_state'] = 2;
		
		$model = Model();
		$renzheng = $model->table('company')->where($condition)->find();
		Tpl::output('renzheng',$renzheng);

		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		
		if($renzheng['company_type']==1){
			$setting = $model->table('setting')->where(array('name'=>'company_shop_cash'))->find();
			Tpl::output('cash',$setting['value']*100);
		}else{
			$setting = $model->table('setting')->where(array('name'=>'shop_cash'))->find();
			Tpl::output('cash',$setting['value']*100);
		}
		
		Tpl::showpage('payment.renzheng');
	}
	
	public function searchOp(){
		Tpl::showpage('search');
	}
	
	
	public function delauctionOp(){
		$condition = array();
		$condition['id'] = intval($_GET['auction_id']);
		$condition['seller_id'] = $_COOKIE['user_id'];
		
		$model = Model();
		$auction = $model->table('auction')->where($condition)->find();
		$res = $model->table('auction')->where($condition)->delete();
		if($res){
			
			$list = $model->table('auction_img')->where(array('auction_id'=>intval($_GET['auction_id'])))->select();
			if(!empty($list)){
				foreach($list as $val){
					if(file_exists(BASE_UPLOAD_PATH.'/shop/auction/'.$auction['auction_add_date'].'/'.$val['auction_img'])){
						unlink(BASE_UPLOAD_PATH.'/shop/auction/'.$auction['auction_add_date'].'/'.$val['auction_img']);
						unlink(bearshop_cut_image(BASE_UPLOAD_PATH.'/shop/auction/'.$auction['auction_add_date'].'/'.$val['auction_img']));
						unlink(bearshop_cut_image(BASE_UPLOAD_PATH.'/shop/auction/'.$auction['auction_add_date'].'/'.$val['auction_img'],1));
					}					
				}
			}			if(file_exists($_SERVER["DOCUMENT_ROOT"].$auction["auction_video"])){				unlink($_SERVER["DOCUMENT_ROOT"].$auction["auction_video"]);			}			
			
			echo json_encode(array('state'=>1));
		}
		exit;	
	}
	
	public function updatestateOp(){
		
		$condition = array();
		$condition['id'] = $_GET['auction_id'];
		$condition['seller_id'] = $_COOKIE['user_id'];
		
		$model = Model();
		$auction_id = intval($_GET['auction_id']);
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		
		$params = array();
		$params['is_state'] = intval($_GET['is_state']);
		if($params['is_state']==1){
			$params['is_liupai'] = '1';
			$params['is_fabu'] = '0';
			$params['is_tuisong'] = '0';
			$params['is_share'] = '1';
			$params['cashprice'] = '0';		
		}
		
	
		$res = $model->table('auction')->where($condition)->update($params);
		if($res){
			if($auction['cashprice']>0){
				$cash_log = $model->table('cash_log')->where(array('auction_id'=>$auction['id']))->find();
				if($cash_log['paymentname']=='weixin'){
					require_once BASE_ROOT_PATH."/shop/templates/default/home/WxPayPubHelper/WxPayPubHelper.php";
					$out_trade_no = $cash_log['pre_order_sn'];
					$refund_fee = $cash_log["cprice"]*100;
					//商户退款单号，商户自定义，此处仅作举例
					$out_refund_no = "refund_cash_sn".time();
					//总金额需与订单号out_trade_no对应，demo中的所有订单的总金额为1分
					$total_fee = $cash_log["cprice"]*100;
					//使用退款接口
					$refund = new Refund_pub();
					$refund->setParameter("out_trade_no","$out_trade_no");//商户订单号
					$refund->setParameter("out_refund_no","$out_refund_no");//商户退款单号
					$refund->setParameter("total_fee","$total_fee");//总金额
					$refund->setParameter("refund_fee","$refund_fee");//退款金额
					$refund->setParameter("op_user_id",WxPayConf_pub::MCHID);//操作员
					//调用结果
					$refundResult = $refund->getResult();
				}else{
					$model->table('user')->where(array('user_id'=>$auction['seller_id']))->setInc('price',$auction['cashprice']);
				}
				
				$model->table('cash_log')->where(array('auction_id'=>$auction['id']))->delete();				
				
				$seller = $model->table('user')->where(array('user_id'=>$auction['seller_id']))->find();
				
				$params = array();
				$params['user_id'] = $seller['user_id'];
				$params['mingxi_type'] = '0';
				$params['mingxi_price'] = $auction['cashprice'];
				$params['add_time'] = time();
				$params['mingxi_reason'] = '保证金退还';
				$params['mingxi_pos'] = '0';
				$model->table('mingxi')->insert($params);
			}
			
			echo json_encode(array('state'=>1));
		}
		exit;
	}
	
	
	public function updateshowOp(){
		$condition = array();
		$condition['id'] = $_GET['auction_id'];
		$condition['seller_id'] = $_COOKIE['user_id'];
		
		$params = array();
		$params['is_show'] = intval($_GET['is_show']);
		
		$model = Model();
		$res = $model->table('auction')->where($condition)->update($params);
		if($res){
			echo json_encode(array('state'=>1));
		}
		exit;
	}
	
	
	public function pingbiOp(){
		
		$model = Model();
		$seller = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		
		$user = $model->table('user')->where(array('user_id'=>intval($_GET['pingbiid'])))->find();
		
		if(intval($_GET['pingbi'])=='1'){
			$params = array();
			$params['seller_id'] = $seller['user_id'];
			$params['seller_name'] = $seller['nickname'];
			$params['user_id'] = $user['user_id'];
			$params['user_name'] = $user['nickname'];
			$params['add_time'] = time();
			
			$model->table('pingbi')->insert($params);
			
		}else{
			$params = array();
			$params['seller_id'] = $seller['user_id'];
			$params['user_id'] = $user['user_id'];
			
			$model->table('pingbi')->where($params)->delete();
		}
		
		echo json_encode(array('state'=>1));
		exit;	
	}
	
	/*
	 * 明细列表
	 */
	public function mingxiOp(){
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		Tpl::showpage('mingxi');
	}
	
	/*
	 * 明细数据
	 */
	public function mingxidataOp(){
				
		$model = Model();
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*10;
		$limit = "{$nextnum},10";
		
		$list = $model->table('mingxi')->where(array('user_id'=>$_COOKIE['user_id']))->order('id desc')->limit($limit)->select();
		
		Tpl::output('list',$list);	
		Tpl::showpage('mingxi.data');
	}
	
	/*
	 * 明细详情
	*/
	public function mingxidetailOp(){
		
		$mingxi_id = intval($_GET['id']);
		
		$model = Model();
		$mingxi = $model->table('mingxi')->where(array('id'=>$mingxi_id))->find();
		Tpl::output('mingxi',$mingxi);
		
		Tpl::showpage('mingxi.detail');	
	}
	
	
	public function renewOp(){
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		$access_token = $this->getAccessTokenApi();
		$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$user['openid']}&lang=zh_CN";
		
		$d = $this->https_request($url);
		$d = json_decode($d,true);

		if($d['errcode']=='40001'){
			$access_token = $this->getAccessToken();
			$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$access_token}&openid={$user['openid']}&lang=zh_CN";
			$d = $this->https_request($url);
			$d = json_decode($d,true);
		}
		
		$data = array();
		$data['avatar'] = $d['headimgurl'];
		$data['nickname'] = $d['nickname'];
		$data['city'] = $d['city'];
		$data['province'] = $d['province'];
		$data['country'] = $d['country'];
		
		$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($data);
		echo json_encode(array('state'=>1));
		exit;
		
	}
	
	
	/*
	 * 查看屏蔽用户
	 */
	public function pingbiviewOp(){
		$model = Model();
		$list = $model->table('pingbi,user')->join('left')->on('pingbi.user_id = user.user_id')->where(array('seller_id'=>$_COOKIE['user_id']))->order('pingbi.id desc')->select();
		
		if(!empty($list)){
			foreach($list as $key=>$val){
				$level = array();
				$level['start'] = array('elt',$val['spoints']);
				$level['end'] = array('gt',$val['spoints']);
				$level['type'] = 1;
				$slevel = $model->table('level')->where($level)->find();
				$list[$key]['level'] = $slevel['name'];
			}
		}
		
		Tpl::output('list',$list);
		
		Tpl::showpage('pingbi.view');		
	}
	
	
}